//
//  JCNetWork.swift
//  JCNewsForMac
//
//  Created by ifly on 13/7/18.
//  Copyright © 2018年 Ismail. All rights reserved.
//

import Cocoa
import Alamofire

class JCNetWork: NSObject {
    
    
   static func post(_ url:String,
              parameters:Dictionary<String, Any>,
              successs:@escaping (Any)->Void,
              failure:@escaping (Error)->Void) -> Void {
        
        print("==========请求地址==========\n",url)
        print("==========参数==========\n",parameters)
        Alamofire.request(url,
                          method: .post,
                          parameters: parameters,
                          encoding: JSONEncoding.default).responseJSON { (resopnseJSON) in
                            
                            
                            print("=",resopnseJSON.result)

                            switch resopnseJSON.result {
                            case .success:
                                if let json = resopnseJSON.result.value {
                                    print("==========请求结果==========\n \(json)")
                                    successs(json)
                                }else{
                                    let err = NSError.init(domain: "服务器数据不是JSON数据！",
                                                           code: 500, userInfo: nil)
                                    failure(err)
                                }
                            default:
                                failure(resopnseJSON.result.error!)
                            }
            
        }
        
        
        
    }
    
    

    

}
